package com.zhengqing.system.api;

import com.zhengqing.common.base.constant.ServiceConstant;
import com.zhengqing.common.base.exception.MyException;
import com.zhengqing.common.core.annotaion.LimiterValite;
import com.zhengqing.common.core.api.BaseController;
import com.zhengqing.system.entity.ManualBrand;
import com.zhengqing.system.model.dto.ManualCatalogToMailDto;
import com.zhengqing.system.model.dto.ManualModelSearchDto;
import com.zhengqing.system.model.vo.ManualModelSearchDetailVo;
import com.zhengqing.system.model.vo.ManualModelSearchVo;
import com.zhengqing.system.service.IManualModelOmService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 基础模块 - 数据字典接口
 * </p>
 *
 * @author des1gn
 * @description
 * @date 2020/4/15 20:50
 */
@Slf4j
@RestController
@RequestMapping(ServiceConstant.SERVICE_API_PREFIX_MINI + "/manual")
public class ManualCatalogMpController extends BaseController {

    @Resource
    private IManualModelOmService manualModelOmService;


    @Autowired
    private HttpServletRequest request;

    @GetMapping("search")
    @LimiterValite
    public List<ManualModelSearchVo> search(ManualModelSearchDto searchDto) {
        if (StringUtils.isBlank(searchDto.getModelName())){
            throw new MyException("请输入你要查找的型号名称");
        }
        return this.manualModelOmService.mpSearchModel(searchDto,request);
    }

    @GetMapping("detail")
    @LimiterValite
    public ManualModelSearchDetailVo detail(String id) {
        if (StringUtils.isBlank(id)){
            throw new MyException("参数错误");
        }
        return this.manualModelOmService.mpSearchModelDetail(id,request);
    }

    @GetMapping("getToEmail")
    @LimiterValite
    public Boolean getToEmail(ManualCatalogToMailDto param){
       return manualModelOmService.mpGetCatalogToEmail(param,request);
    }

    @GetMapping("getAllBrand")
    @LimiterValite
    public List<ManualBrand> getAllBrand() {
        return this.manualModelOmService.getAllBrand(request);
    }



}
